<template>
	<view class="ys">
		<view class="example-body">
			<uni-datetime-picker type="date" :value="time" @change="change" />
		</view>
		<view class="box" v-for="(item,index) in list" :key="index" @click="toPage('./hisdetail?id='+item.id)">
			<view class="title">
				<text>房间名 : {{room.name}}</text>
			</view>
			<view class="info">
				<view class="avatar_path" :style="{backgroundImage:`url(${item.leader.avatar_path})`}">
				</view>
				<view class="right">
					<view class="name">
						开始时间 : {{item.create_time}}
					</view>
					<view class="name">
						完成时间 : {{item.finish_time}}
					</view>
					<view class="name">
						{{item.leader.role.text}} : {{item.leader.name}}
					</view>
				</view>
			</view>

		</view>
		<view class="no-list" v-if="list.length == 0">
			<image src="/static/index/nolist.png" mode="widthFix"></image>
			- 暂无数据 -
		</view>
	</view>
</template>

<script>
	import {
		getRoomHistoryOrder,
	} from "@/api/user.js"
	export default {
		data() {
			return {
				loading: false,
				leader: [],
				room: [],
				info: [],
				list: [],
				id: '',
				time: '',
				page: 1,
				last_page: 1,
			}
		},
		onLoad(e) {
			if (e.id) {
				this.id = e.id
				// var date = new Date(),
				// 	year = date.getFullYear(),
				// 	month = date.getMonth() + 1,
				// 	day = date.getDate();
				// month >= 1 && month <= 9 ? (month = "0" + month) : "";
				// day >= 0 && day <= 9 ? (day = "0" + day) : "";
				// this.time = year + '-' + month + '-' + day;
				this.getRoomDetail()
			}
		},
		methods: {
			change(e) {
				this.time = e
				this.list = []
				this.page = 1
				this.last_page = 1
				this.getRoomDetail()
			},
			getRoomDetail() {
				getRoomHistoryOrder({
					room_id: this.id,
					page: this.page,
					date: this.time
				}).then(res => {
					if (res.code == 0) {
						this.list = this.list.concat(res.data.list.data)
						this.last_page = res.data.list.last_page
						this.room = res.data.room
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		padding-bottom: 60px;
	}

	.btns {
		position: fixed;
		bottom: 0;
		width: 100%;
		max-width: 500px;
		left: 50%;
		transform: translate(-50%);
		padding: 10px 0;
		background: #fff;

		.btn {
			margin: 0 auto;
		}
	}

	.box {
		background: #fff;
		border-radius: 10px;
		width: 96%;
		margin: 10px auto;
		padding: 10px;
		box-sizing: border-box;

		.title {
			font-weight: bold;
			font-size: 17px;
			position: relative;
			padding-bottom: 10px;

			&::after {
				position: absolute;
				width: 40px;
				height: 5px;
				background: $uni-bg-color;
				content: '';
				left: 0;
				bottom: 0;
				border-radius: 20px;
			}
		}

		.name {
			padding: 3px 10px;
			font-size: 15px;
		}

		.info {
			display: flex;
			align-items: center;
			padding-top: 10px;

			.avatar_path {
				width: 75px;
				height: 75px;
				background-size: 100% 100%;
				border-radius: 5px;
			}

			.right {
				width: calc(100% - 75px);
				padding-left: 10px;
			}
		}

		.item {
			background: #fff;
			border-radius: 6px;
			box-sizing: border-box;
			width: 100%;
			margin-bottom: 15px;
			display: flex;
			align-items: center;

			.right {

				box-sizing: border-box;
				display: flex;
				align-items: center;



				.username {
					font-weight: bold;
					font-size: 14px;
					display: flex;
					align-items: center;

					text {
						margin-left: 10px;
						background: $uni-bg-color;
						font-size: 12px;
						color: #fff;
						padding: 2px 8px;
						border-radius: 4px;
					}
				}

				.phone {
					margin: 5px 0;
					font-size: 13px;
				}

				.time {
					color: #777;
					font-size: 12px;
				}
			}

			.btn-group {
				display: flex;
				justify-content: flex-end;
				width: 100px;

				button {
					font-size: 12px;
					margin: 0;
					padding: 0;
					width: 60px;
					background: #b60000;
					color: #fff;
				}
			}
		}
	}
</style>